package kryo;

import Domain.User;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import jacson.JacsonDemo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * MyUser: Александр
 * Date: 30.11.13
 * Time: 15:14
 * To change this template use File | Settings | File Templates.
 */
public class KryoDemo {

    private static Kryo kryo = new Kryo();

    public static void main(String[] args) throws IOException {
        readObjectWithKryo();
       // writeObject();
    }

    private static void readObjectWithKryo() throws FileNotFoundException {
        Input input = new Input(new FileInputStream("file.bin"));

        User user = kryo.readObject(input, User.class);
        input.close();
        System.out.println(user);

    }

    private static void writeObject() throws IOException {
        User user = JacsonDemo.readData();

        Output output = new Output(new FileOutputStream("file.bin"));
        kryo.writeObject(output, user);
        output.close();
    }
}
